<template>
  <div>
    <video ref="videoPlayer" class="video-js"></video>
  </div>
</template>

<script>
import videojs from 'video.js';
import 'video.js/dist/video-js.css';

export default {
  mounted() {
    // 初始化视频播放器
    this.player = videojs(this.$refs.videoPlayer, this.options, function onPlayerReady() {
      console.log('Video.js player is ready');
    });

    // 监听播放状态
    this.player.on('play', this.handlePlay);
    this.player.on('pause', this.handlePause);
  },
  data() {
    return {
      player: null,
      options: {
        // Video.js 配置选项
        controls: true,
        autoplay: false,
        preload: 'auto'
        // 其他配置选项...
      }
    };
  },
  methods: {
    handlePlay() {
      // 视频播放时，保持显示
      this.$refs.videoPlayer.style.display = 'block';
    },
    handlePause() {
      // 视频暂停时，隐藏播放器
      this.$refs.videoPlayer.style.display = 'none';
    }
  },
  beforeDestroy() {
    // 在组件销毁前，销毁播放器以释放资源
    if (this.player) {
      this.player.dispose();
    }
  }
};
</script>
